<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\lists;
use DB;

class ListsController extends Controller
{
      public function index()
      {
        $lists = DB::table('lists')->orderBy('family')->where('deleted_at','=',NULL)->get();
        $lists_f = DB::table('lists')->orderBy('family')->where('deleted_at','<>',NULL)->get();
        return view('backend.list.index',compact('lists','lists_f'));
      }

      public function store(Request $request)
      {
        $this->validate($request,[
          'name'=>'required',
          'family'=>'required'
        ]);

        $lists = lists::create([
          'name'=> $request->name,
          'family'=> $request->family
        ]);
        session()->flash('success','任务创建成功！');
        return redirect()->back();
      }

      public function finish($id)
    {

      $lists = lists::findOrFail($id);
      $lists->delete();
      session()->flash('success','任务删除成功！');
      return redirect()->back();
    }

    public function destroy($id)
  {

    $lists = lists::findOrFail($id);
    $lists->forceDelete();
    session()->flash('success','任务删除成功！');
    return redirect()->back();
  }
}
